/*
 * Copyright (C) 2013 tangzhi
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.tangzsoft.pdmviewer;


/**
 *
 * @author tangzhi
 */
public class MainView extends javax.swing.JFrame {
    
    /**
     * 界面控制器
     */
    InterfaceControler ifc = new InterfaceControler(this);
    
    /**
     * 导航树控制器
     */
    public NavTreeControler ntc = new NavTreeControler(this);
    
    
    public ViewControler vc = new ViewControler(this);
    
    /**
     * Creates new form MainView
     */
    public MainView() {
        initComponents();
        
        //窗口居中显示
        setLocationRelativeTo(null);
        
        
        ntc.initPdmViewerTree(pnlProject);
        
        vc.init(tplMain);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlTop = new javax.swing.JPanel();
        pnlToobar = new javax.swing.JPanel();
        tbrGeneral = new javax.swing.JToolBar();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btnOpen = new javax.swing.JButton();
        tbrSearch = new javax.swing.JToolBar();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        tfdSearch = new javax.swing.JTextField();
        pnlCenter = new javax.swing.JPanel();
        splMain = new javax.swing.JSplitPane();
        pnlLeft = new javax.swing.JPanel();
        splNav = new javax.swing.JSplitPane();
        tplNav = new javax.swing.JTabbedPane();
        pnlProject = new javax.swing.JPanel();
        splProject = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        tplProps = new javax.swing.JTabbedPane();
        pnlProperties = new javax.swing.JPanel();
        tplMain = new javax.swing.JTabbedPane();
        pnlMain = new javax.swing.JPanel();
        pnlFilter = new javax.swing.JPanel();
        pnlScope = new javax.swing.JPanel();
        lblScope = new javax.swing.JLabel();
        cbxTable = new javax.swing.JCheckBox();
        cbxColumn = new javax.swing.JCheckBox();
        cbxSequence = new javax.swing.JCheckBox();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        pnlFilterContent = new javax.swing.JPanel();
        tfdFilter = new javax.swing.JTextField();
        splWork = new javax.swing.JSplitPane();
        splObjects = new javax.swing.JScrollPane();
        tblObjects = new javax.swing.JTable();
        tplDetails = new javax.swing.JTabbedPane();
        pnlBottom = new javax.swing.JPanel();
        mbrMain = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PdmViewer");
        getContentPane().setLayout(new java.awt.BorderLayout(0, 3));

        pnlTop.setLayout(new javax.swing.BoxLayout(pnlTop, javax.swing.BoxLayout.Y_AXIS));

        pnlToobar.setLayout(new java.awt.BorderLayout());

        tbrGeneral.setFloatable(false);
        tbrGeneral.setRollover(true);
        tbrGeneral.add(jSeparator1);

        btnOpen.setText("Open");
        btnOpen.setFocusable(false);
        btnOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fnOpenFile(evt);
            }
        });
        tbrGeneral.add(btnOpen);

        pnlToobar.add(tbrGeneral, java.awt.BorderLayout.CENTER);

        tbrSearch.setFloatable(false);
        tbrSearch.setRollover(true);
        tbrSearch.setMaximumSize(new java.awt.Dimension(280, 2147483647));
        tbrSearch.setMinimumSize(new java.awt.Dimension(280, 32));
        tbrSearch.setPreferredSize(new java.awt.Dimension(280, 32));
        tbrSearch.add(jSeparator2);

        tfdSearch.setText("Search...");
        tfdSearch.setPreferredSize(new java.awt.Dimension(260, 28));
        tbrSearch.add(tfdSearch);

        pnlToobar.add(tbrSearch, java.awt.BorderLayout.EAST);

        pnlTop.add(pnlToobar);

        getContentPane().add(pnlTop, java.awt.BorderLayout.NORTH);

        pnlCenter.setLayout(new javax.swing.BoxLayout(pnlCenter, javax.swing.BoxLayout.Y_AXIS));

        splMain.setDividerLocation(220);

        pnlLeft.setLayout(new javax.swing.BoxLayout(pnlLeft, javax.swing.BoxLayout.Y_AXIS));

        splNav.setDividerLocation(320);
        splNav.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        splNav.setMinimumSize(new java.awt.Dimension(150, 203));

        tplNav.setMinimumSize(new java.awt.Dimension(87, 0));

        pnlProject.setLayout(new java.awt.GridLayout(1, 0));

        splProject.setViewportView(jTree1);

        pnlProject.add(splProject);

        tplNav.addTab("Project", pnlProject);

        splNav.setTopComponent(tplNav);

        tplProps.setMaximumSize(new java.awt.Dimension(32767, 191));
        tplProps.setMinimumSize(new java.awt.Dimension(107, 190));

        org.jdesktop.layout.GroupLayout pnlPropertiesLayout = new org.jdesktop.layout.GroupLayout(pnlProperties);
        pnlProperties.setLayout(pnlPropertiesLayout);
        pnlPropertiesLayout.setHorizontalGroup(
            pnlPropertiesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 193, Short.MAX_VALUE)
        );
        pnlPropertiesLayout.setVerticalGroup(
            pnlPropertiesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 145, Short.MAX_VALUE)
        );

        tplProps.addTab("Properties", pnlProperties);

        splNav.setRightComponent(tplProps);

        pnlLeft.add(splNav);

        splMain.setLeftComponent(pnlLeft);

        pnlMain.setLayout(new java.awt.BorderLayout());

        pnlFilter.setPreferredSize(new java.awt.Dimension(705, 35));
        pnlFilter.setLayout(new javax.swing.BoxLayout(pnlFilter, javax.swing.BoxLayout.LINE_AXIS));

        pnlScope.setMinimumSize(new java.awt.Dimension(0, 2147483647));
        pnlScope.setLayout(new javax.swing.BoxLayout(pnlScope, javax.swing.BoxLayout.LINE_AXIS));

        lblScope.setText("scope:");
        lblScope.setMaximumSize(new java.awt.Dimension(50, 16));
        lblScope.setMinimumSize(new java.awt.Dimension(50, 16));
        lblScope.setPreferredSize(new java.awt.Dimension(50, 16));
        pnlScope.add(lblScope);

        cbxTable.setText("Table");
        pnlScope.add(cbxTable);

        cbxColumn.setText("Column");
        pnlScope.add(cbxColumn);

        cbxSequence.setText("Sequence");
        pnlScope.add(cbxSequence);
        pnlScope.add(filler1);

        pnlFilter.add(pnlScope);

        pnlFilterContent.setMaximumSize(new java.awt.Dimension(200, 2147483647));
        pnlFilterContent.setMinimumSize(new java.awt.Dimension(200, 28));
        pnlFilterContent.setPreferredSize(new java.awt.Dimension(200, 35));

        tfdFilter.setText("Filter Objects...");

        org.jdesktop.layout.GroupLayout pnlFilterContentLayout = new org.jdesktop.layout.GroupLayout(pnlFilterContent);
        pnlFilterContent.setLayout(pnlFilterContentLayout);
        pnlFilterContentLayout.setHorizontalGroup(
            pnlFilterContentLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(tfdFilter, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        pnlFilterContentLayout.setVerticalGroup(
            pnlFilterContentLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(tfdFilter, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pnlFilter.add(pnlFilterContent);

        pnlMain.add(pnlFilter, java.awt.BorderLayout.NORTH);

        splWork.setDividerLocation(150);
        splWork.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        splWork.setPreferredSize(new java.awt.Dimension(762, 438));

        tblObjects.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "No.", "Name", "Type", "Comment"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Long.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        splObjects.setViewportView(tblObjects);

        splWork.setTopComponent(splObjects);
        splWork.setRightComponent(tplDetails);

        pnlMain.add(splWork, java.awt.BorderLayout.CENTER);

        tplMain.addTab("Viewer", pnlMain);

        splMain.setRightComponent(tplMain);

        pnlCenter.add(splMain);

        getContentPane().add(pnlCenter, java.awt.BorderLayout.CENTER);

        pnlBottom.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), null));
        pnlBottom.setPreferredSize(new java.awt.Dimension(950, 25));

        org.jdesktop.layout.GroupLayout pnlBottomLayout = new org.jdesktop.layout.GroupLayout(pnlBottom);
        pnlBottom.setLayout(pnlBottomLayout);
        pnlBottomLayout.setHorizontalGroup(
            pnlBottomLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 837, Short.MAX_VALUE)
        );
        pnlBottomLayout.setVerticalGroup(
            pnlBottomLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 23, Short.MAX_VALUE)
        );

        getContentPane().add(pnlBottom, java.awt.BorderLayout.SOUTH);

        jMenu1.setText("File");
        mbrMain.add(jMenu1);

        jMenu2.setText("Edit");
        mbrMain.add(jMenu2);

        setJMenuBar(mbrMain);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fnOpenFile(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fnOpenFile
        
        ifc.fnOpenFile(evt);
        
    }//GEN-LAST:event_fnOpenFile

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        
        /**
         * 使用系统屏幕菜单
         */
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOpen;
    private javax.swing.JCheckBox cbxColumn;
    private javax.swing.JCheckBox cbxSequence;
    private javax.swing.JCheckBox cbxTable;
    private javax.swing.Box.Filler filler1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JTree jTree1;
    private javax.swing.JLabel lblScope;
    private javax.swing.JMenuBar mbrMain;
    private javax.swing.JPanel pnlBottom;
    private javax.swing.JPanel pnlCenter;
    private javax.swing.JPanel pnlFilter;
    private javax.swing.JPanel pnlFilterContent;
    private javax.swing.JPanel pnlLeft;
    private javax.swing.JPanel pnlMain;
    private javax.swing.JPanel pnlProject;
    private javax.swing.JPanel pnlProperties;
    private javax.swing.JPanel pnlScope;
    private javax.swing.JPanel pnlToobar;
    private javax.swing.JPanel pnlTop;
    private javax.swing.JSplitPane splMain;
    private javax.swing.JSplitPane splNav;
    private javax.swing.JScrollPane splObjects;
    private javax.swing.JScrollPane splProject;
    private javax.swing.JSplitPane splWork;
    private javax.swing.JTable tblObjects;
    private javax.swing.JToolBar tbrGeneral;
    private javax.swing.JToolBar tbrSearch;
    private javax.swing.JTextField tfdFilter;
    private javax.swing.JTextField tfdSearch;
    private javax.swing.JTabbedPane tplDetails;
    private javax.swing.JTabbedPane tplMain;
    private javax.swing.JTabbedPane tplNav;
    private javax.swing.JTabbedPane tplProps;
    // End of variables declaration//GEN-END:variables
}
